package com.xinshujia.wxxcx.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xinshujia.wxxcx.pojos.entity.AlarmRecord;
import com.xinshujia.wxxcx.pojos.info.AccelerationInfo;
import com.xinshujia.wxxcx.pojos.info.AlarmRecordCause;
import com.xinshujia.wxxcx.pojos.info.AlarmRecordInfo;
import com.xinshujia.wxxcx.pojos.info.AlarmRecordNumInfo;
import com.xinshujia.wxxcx.pojos.view.AlarmRecordView;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author Cui Han
 * @Date 2024/5/17 16:02
 * @Description: TODO
 * @Version 1.0
 */
@Mapper
public interface AlarmRecordMapper extends BaseMapper<AlarmRecord> {

    @Select("SELECT * FROM alarm_record_view  where company=#{company} ORDER BY date DESC LIMIT 50;")
    List<AlarmRecordView> findAlarmRecord(String company);

    @Select("select id, photo,user,cause from alarm_record where id = #{id}")
    AlarmRecordCause selectAlarmCause(Integer id);

    @Update("update alarm_record set photo = #{photo},cause = #{cause},user = #{user},dispose=#{dispose} where id=#{id}")
    void updateAlarmCause(AlarmRecord alarmRecord);

    @Select("select machine_name,num from alarm_record_num where company=#{company}")
    List<AlarmRecordNumInfo> findAlarmRecordNum(String company);
    @Insert("INSERT INTO alarm_record (production_line_id,machine_id,company,device,dispose,`date`,`status`) values (#{productionLineId},#{machineId},#{company},#{device},#{dispose},#{date},#{status})")
    void insertAlarmRecord(AlarmRecord alarmRecord);

    @Select("select machine_id,device,`status` from alarm_record where status = 3 and company = #{company}")
    AlarmRecordInfo selectAlarm(String company);

    @Select("select machine_id,device,`status` from alarm_record where status = 3  LIMIT 1 ")
    AlarmRecordInfo selectListAlarm();

    @Update("update alarm_record set status = 0 where machine_id = #{machineId} and status != 0")
    void updateMachineId(Long machineId);

    @Select("select * from alarm_record where device = #{guid} and status = 3 ")
    AlarmRecord selectStatus(String guid);
}
